package marvin.webapp.audio.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MagicTool {
	public static List<File> getSupportedChildren(File parent) {
		List<File> files = new ArrayList<File>();

		if (parent != null && parent.isDirectory() && parent.listFiles() != null) {
			for (File child : parent.listFiles()) {
				if (child.isDirectory()
						|| child.getAbsolutePath().endsWith(".mp3")
						|| child.getAbsolutePath().endsWith(".wav")
						|| child.getAbsolutePath().endsWith(".wma"))
					files.add(child);
			}
		}
		
		java.util.Collections.sort(files);

		return files;
	}

	public static List<File> getOnlyFiles(File parent) {
		List<File> files = new ArrayList<File>();

		if (parent.isDirectory()) {
			for (File child : parent.listFiles()) {
				if (child.getAbsolutePath().endsWith(".mp3")
						|| child.getAbsolutePath().endsWith(".wav")
						|| child.getAbsolutePath().endsWith(".wma"))
					files.add(child);
				else if(child.isDirectory()){
					files.addAll(getOnlyFiles(child));
				}
			}
		}

		return files;
	}
}
